package com.group.dao;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Repository;

import com.group.model.News;
import com.group.model.NewsFlash;
import com.group.model.Suggestion;
import com.group.model.Tag;

@Repository
public interface NewsDao {

	public List<Tag> queryTag(@Param("key") String key, @Param("start") Integer start, @Param("limit") Integer limit);

	public int queryTagCount(@Param("key") String key);

	// @Cacheable("queryNews")
	public List<News> queryNews(@Param("key") String key, @Param("type") String type, @Param("tagName") String tagName, @Param("state") Integer state, @Param("sort") String sort, @Param("isHot") Integer isHot, @Param("start") Integer start, @Param("limit") Integer limit);

	public int queryNewsCount(@Param("key") String key, @Param("type") String type, @Param("tagName") String tagName, @Param("state") Integer state, @Param("sort") String sort, @Param("isHot") Integer isHot);

	public List<News> queryNewsByCid(@Param("cid") String cid, @Param("type") String type, @Param("state") Integer state, @Param("start") Integer start, @Param("limit") Integer limit);

	public int queryNewsByCidCount(@Param("cid") String cid, @Param("type") String type, @Param("state") Integer state);

	@Select("select t.* from tag t where t.id in (select nt.tagId from newstag nt where nt.newsId = #{0})")
	public List<Tag> queryNewsTag(Long newsId);

	public List<NewsFlash> queryNewsFlash(@Param("key") String key, @Param("state") Integer state, @Param("start") Integer start, @Param("limit") Integer limit);

	public int queryNewsFlashCount(@Param("key") String key, @Param("state") Integer state);

	public List<Suggestion> querySuggestion(@Param("key") String key, @Param("start") Integer start, @Param("limit") Integer limit);

	public int querySuggestionCount(@Param("key") String key);

	@Select("select n.id , n.read ,n.title,n.state,n.createTime from news n where n.state = 1 and n.createTime >= date_add(now(), interval - 3 hour) and n.specialType = 0")
	public List<News> querySpecialNews0();

	@Select("select n.id , n.read ,n.title,n.state,n.createTime from news n where n.state = 1 and n.createTime >= date_add(now(), interval - 3 hour) and n.specialType = 1")
	public List<News> querySpecialNews1();

	@Select("select n.id , n.read ,n.title,n.state,n.createTime from news n where n.state = 1 and n.createTime >= date_add(now(), interval - 3 hour) and n.specialType = 2")
	public List<News> querySpecialNews2();

	@Select("select n.id , n.read ,n.title,n.state,n.createTime from news n where n.state = 1 and n.createTime >= date_add(now(), interval - 6 hour) and n.specialType = 2 and n.createTime <= date_add(now(), interval - 3 hour)")
	public List<News> querySpecialNews21();

}
